package io.zhengsh.order.bean;

import io.zhengsh.order.annotaion.Anno;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
    private final Set<Object> earlyProxyReferences = Collections.newSetFromMap(new ConcurrentHashMap<>(16));

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization ....");
        if (bean instanceof ITestBean) {
            BoyAndGirlMethodInterceptor interceptor = new BoyAndGirlMethodInterceptor();
            Object proxyBean = interceptor.warpBean( bean, beanName);
            earlyProxyReferences.add(beanName);
            return proxyBean;

        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("The postProcessAfterInitialization method is calling.");
        return bean;
    }
}